package br.com.cogerh.sidec.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;



@Entity
@Table(schema = "adm")
public class Reuniao {
	@Id
	@GeneratedValue
	@Column(name ="id_reuniao")
	private Integer id;
	private String nome;
	private Date dataReuniao;

	
	@ManyToMany(fetch = FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)  
	@JoinTable(name = "participantes_reuniao", schema = "adm")
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	private Set<Pessoa> listaParticipantes;

	public Reuniao() {
		listaParticipantes = new HashSet<>();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	

	public Date getDataReuniao() {
		return dataReuniao;
	}

	public void setDataReuniao(Date dataReuniao) {
		this.dataReuniao = dataReuniao;
	}

	public Set<Pessoa> getListaParticipantes() {
		return listaParticipantes;
	}

	public void setListaParticipantes(Set<Pessoa> listaParticipantes) {
		this.listaParticipantes = listaParticipantes;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dataReuniao == null) ? 0 : dataReuniao.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime
				* result
				+ ((listaParticipantes == null) ? 0 : listaParticipantes
						.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Reuniao other = (Reuniao) obj;
		if (dataReuniao == null) {
			if (other.dataReuniao != null)
				return false;
		} else if (!dataReuniao.equals(other.dataReuniao))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (listaParticipantes == null) {
			if (other.listaParticipantes != null)
				return false;
		} else if (!listaParticipantes.equals(other.listaParticipantes))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		return true;
	}

	
	
}
